<template>
  <el-select :value="value" placeholder="请选择门店" clearable :style="{ 'width': width }" @change="change">
    <el-option v-for="restaurant in restaurantList" :key="restaurant" :label="restaurant" :value="restaurant"></el-option>
  </el-select>
</template>

<script>
/**
 * 业务组件 -
 */
export default {
  name: 'UesRestaurant',
  props: {
    /** 数据源 */
    value: {
      type: String,
      default: ''
    },
    /** 宽度 */
    width: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      api: this.$u.api.PluginsDineparkConfig,
      // 分组
      restaurantList: []
    }
  },
  created() {
    // 初始化数据
    this.initData()
  },
  // watch: {
  //   themeId(newVal, oldVal) {
  //     if (newVal) {
  //       this.value = ''
  //       this.initData()
  //     }
  //   }
  // },
  methods: {
    // 初始化数据
    initData() {
      this.api.fetch().then(res => {
        const restaurantString = res.data.depts
        const restaurantArray = JSON.parse(restaurantString)
        this.restaurantList = restaurantArray.map(item => item.title)
        console.log('餐厅', this.restaurantList)
      })
    },
    change(e) {
      this.$emit('input', e)
      this.$emit('change', e)
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep{
  .el-input{
    width: 100% !important;
  }
}
</style>
